package com.yh.chapter1.pojo;

import java.io.Serializable;

/**
 * @ClassName Person
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/4 10:01
 */
public class Person implements Cloneable, Serializable {
    final int demo = 10;
    private String pname;
    private int age;
    private Address address;

    static {
        System.out.println("我是静态代码块父");
    }

    public Person() {
        System.out.println("我是Person");
    }

    public Person(String name, int age) {
        this.pname = name;
        this.age = age;
        this.address = new Address();
    }

    public Person getInstance(String name, int age) {
        return new Person(name, age);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public void setAddress(String provinces, String city) {
        address.setAddress(provinces, city);
    }

    public void display(String name) {
        System.out.println(name + ":pname=" + pname + ",age=" + age + "," + address);
    }

    public String getName() {
        return pname;
    }

    public void setName(String name) {
        this.pname = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || (getClass() != o.getClass())) {
            return false;
        }
        Person person = (Person) o;
        return person.getName().equals(this.getName()) && person.getAge() == this.getAge();
    }

    @Override
    public int hashCode() {
        int result = pname != null ? pname.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }
}
